<?php
    $top_menu_1 = FALSE;
    $top_menu_2 = FALSE;
    $top_menu_3 = FALSE;
    $top_menu_4 = FALSE;
    $top_menu_5 = FALSE;
    $top_menu_6 = FALSE;
    $top_menu_7 = FALSE;
    include('header.php');
    include('sidebar2.php');
    
    if(isset($_SESSION['m_id'])){
        $m_id = $_SESSION['m_id'];
        $sql = "SELECT * FROM hs_member WHERE m_id = $m_id";
        $line = $db->queryUniqueObject($sql);
    }
?>
            <div id="main_content" class="register_content">
                <img src="images/user_info_title.jpg" alt="Order" id="user_info_title" />
                <p id="link_to_qoute">
                    <a href="qoute-history.php" title="My Qoute History" <?php if(!isset($_SESSION['m_id'])){ echo 'class="display_none"'; } ?>>My Quote History</a>
                </p>
                
                <form name="regis_frm" id="regis_frm" <?php if(!isset($_SESSION['m_id'])){ echo 'class="display_none"'; } ?>>
                
                <div class="regis_frm">
                    <span>Email Address :</span>
                    <input type="text" name="email" id="email" readonly='readonly' value="<?php echo $line->m_email; ?>" />
                </div>
                
                <div class="regis_frm">
                    <span>Old Password :</span>
                    <input type="password" name="o_password" id="o_password" value="" /> *
                </div>
                
                <div class="regis_frm">
                    <span>New Password :</span>
                    <input type="password" name="n_password" id="n_password" value="" />
                </div>
                
                <div class="regis_frm">
                    <span>Confirm Password :</span>
                    <input type="password" name="c_password" id="c_password" value="" />
                </div>
                
                <div class="regis_frm">
                    <span>First Name :</span>
                    <input type="text" name="f_name" id="f_name" value="<?php echo $line->m_name; ?>" /> *
                </div>
                
                <div class="regis_frm">
                    <span>Last Name :</span>
                    <input type="text" name="l_name" id="l_name" value="<?php echo $line->m_lastname; ?>" /> *
                </div>
                
                <div class="regis_frm">
                    <span>Company Name :</span>
                    <input type="text" name="c_name" id="c_name" value="<?php echo $line->m_company; ?>" /> *
                </div>
                
                <div class="regis_frm">
                    <span>Position :</span>
                    <input type="text" name="position" id="position" value="<?php echo $line->m_position; ?>" />
                </div>
                
                <div class="regis_frm">
                    <span>Phone :</span>
                    <input type="text" name="phone" id="phone" value="<?php echo $line->m_phone; ?>" /> *
                </div>
                
                <div class="regis_frm">
                    <span>URL :</span>
                    <input type="text" name="url" id="url" value="<?php echo $line->m_url; ?>" />
                </div>
                
                <div class="regis_frm">
                    <span>Shipping Address :</span>
                    <input type="text" name="address" id="address" value="<?php echo $line->m_address; ?>" /> *
                </div>
                
                <div class="regis_frm">
                    <span>City :</span>
                    <input type="text" name="city" id="city" value="<?php echo $line->m_city; ?>" /> *
                </div>
                
                <div class="regis_frm">
                    <span>Zip/Postal Code :</span>
                    <input type="text" name="post_code" id="post_code" value="<?php echo $line->m_postcode; ?>" /> *
                </div>
                
                <div class="regis_frm">
                    <span>State :</span>
                    <input type="text" name="state" id="state" value="<?php echo $line->m_state; ?>" />
                </div>
                
                <div class="regis_frm">
                    <span>Country :</span>
                    <input type="text" name="country" id="country" value="<?php echo $line->m_country; ?>" /> *
                </div>
                
                <div class="regis_frm2">
                    <span>Receive newsletter :</span>
                    <input type="checkbox" name="newsletter" id="newsletter" value="1" <?php if($line->m_enews==1){ echo 'checked="checked"'; } ?> />
                </div>
                
                <div class="regis_frm">
                    <span class="span_small">How you know<br />Hong chiao?</span>
                    <input type="text" name="know" id="know" value="<?php echo $line->m_knowhow; ?>" /> *
                </div>
                </form>
                
                <div class="regis_frm <?php if(!isset($_SESSION['m_id'])){ echo 'display_none'; } ?>">
                    <span>&nbsp;</span>
                    <img src="images/register_submit_bt.jpg" alt="submit" id="register_submit_bt" class="img_link"/>
                    <img src="images/ajax-loader.gif" alt="submit" id="ajax_loader" class="display_none" />
                </div>
                
                <div id="success_msg2" class="<?php if(isset($_SESSION['m_id'])){ echo 'display_none'; } ?>">
                <?php
                    echo $status_msg['must_login'];
                ?>
                </div>
            </div>
            <div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/jquery.scrollTo-min.js"></script>
<script>
    $(function() {
        $("#regis_frm").validate({
            rules: {
                f_name : "required",
                l_name : "required",
                c_name : "required",
                email: {
                    required: true,
                    email: true
                },
                phone: "required",
                address: "required",
                city: "required",
                post_code: {
                    required: true,
                    number:true
                },
                country: "required",
                know: "required",
                o_password: "required",
                c_password: {
                    equalTo: "#n_password"
                }
            },
            messages: {
                f_name: "Please enter your firstname",
                l_name: "Please enter your lastname",
                c_name: "Please enter your company name",
                email: {
                    required: "Please enter an email address",
                    email: "Please enter a valid email address"
                },
                phone: "Please enter your phone number",
                address: "Please enter your address",
                city: "Please enter your city",
                city: "Please enter your city",
                post_code: {
                    required: "Please enter a postcode",
                    email: "Please enter a valid postcode"
                },
                country: "Please enter your country",
                know: "Please enter this field",
                o_password: "Please enter your password",
                c_password: {
                    equalTo: "Please enter the same password as above"
                }
            }
        });
        
        $('#register_submit_bt').click(function(){
            if($("#regis_frm").valid()){
                $("#register_submit_bt").css('display','none');
                $("#ajax_loader").css('display','block');
                var str = $("#regis_frm").serialize();
                $.post("function/update-user-info.php", str ,function(data){
                    if(trim(data.status)=='success'){
                        alert(data.msg);
                        $("#register_submit_bt").css('display','block');
                        $("#ajax_loader").css('display','none');
                    }else{
                        alert(data.msg);
                        $("#register_submit_bt").css('display','block');
                        $("#ajax_loader").css('display','none');
                        $("#o_password").focus();
                    }
                },'json');
            }else{
                $.scrollTo( '#regis_frm' , 1000);
            }
        });
    });
</script>